#include "internalhtml.h"
#include "mainwindow.h"
#include "control.h"

MainWindow::MainWindow()
{
    captions.push_back("Shelf || Buttons? buttons? we don't need no stinkin' buttons!");
    captions.push_back("Shelf || Who needs a UI anyway");
    captions.push_back("Shelf || When geeks were geeks and mice were rodents");
    captions.push_back("Shelf || But will it blend?");
    captions.push_back("Shelf || I for one welcome our no-button overlords!");
    captions.push_back("Shelf || Now also available in cherry flavor!");
    captions.push_back("Shelf || Who the hell would want to use a browser without a UI! Ridiculous!");
    captions.push_back("Shelf || I'm sorry, what?");
    captions.push_back("Shelf || Life is like a box of chocolates... hmmmmm chocolates...");
    captions.push_back("Shelf || This is unix! I know this!");
    captions.push_back("Shelf || Skynet is upon us");
    captions.push_back("Shelf || The perfect tool to look like a hax0r without doing the hard work!");
    captions.push_back("Shelf || I don't think we've met...");
    captions.push_back("Shelf || Dating was never this unlikely!");
    captions.push_back("Shelf || My, it's dark in here!");
    captions.push_back("Shelf || I like bouncy things");
    captions.push_back("Shelf || Have you been outside lately?");
    captions.push_back("Shelf || Less is more!");
    captions.push_back("Shelf || I like bunnies.");
    captions.push_back("Shelf || Weak as I am, no tears for you!");
    captions.push_back("Shelf || All that is wrong, condensed in a single application!");
    captions.push_back("Shelf || ~s/S// ~s/f/lo!/");
    captions.push_back("Shelf || All you need to do, is ask the right questions");
    captions.push_back("Shelf || Wake up, Neo");
    captions.push_back("Shelf || Follow the white rabbit");
    captions.push_back("Shelf || Not suitable for anyone");
    captions.push_back("Shelf || Parental advisory: contains secret IM language");
    captions.push_back("Shelf || Videogames ate my soul");
    captions.push_back("Shelf || The roof is on fire!");
    srand(time(NULL));
    int index = ((float)rand()/RAND_MAX)*captions.size();
    set_title(captions[index].c_str());
    set_size_request(640,480);
    set_icon_from_file("shelficon_tiny.png");

    Control::Instance()->Shelf_consoleView = new WebWidget();
    Control::Instance()->Shelf_consoleView->hookConsoleFunctions();

    vbox.pack_end(*(Control::Instance()->Shelf_consoleView->getWidget()), false, false);
    Control::Instance()->Shelf_consoleView->getWidget()->set_size_request(-1,100);
    vbox.pack_start(Control::Instance()->notebook, true, true);

    char consolepath[520];
    char path[500];
    getcwd(path, 499);
    sprintf(consolepath, "file://%s/shelfconsole.html", path);
    Control::Instance()->Shelf_consoleView->open(consolepath);

    add(vbox);
    show_all_children();

    Control::Instance()->newShelf(std::string(SHELF_HOME), true);
}

void MainWindow::addConsole(Gtk::Widget* console)
{
    vbox.pack_end(*(console), false, false);
}

void MainWindow::addShelf(std::string uri)
{
    std::cout << "opening new shelf\n\n";
    Control::Instance()->webviews.push_back(new WebWidget());
    Control::Instance()->windows.push_back(new Gtk::ScrolledWindow());
    Control::Instance()->windows.back()->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS);
    Control::Instance()->windows.back()->add(*(Control::Instance()->webviews.back()->getWidget()));
    Control::Instance()->notebook.append_page(*(Control::Instance()->windows.back()));//, "shelf");
    Control::Instance()->webviews.back()->open(uri);
}
